<?php

namespace App\Providers;

use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Queue;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobProcessed;
use App\Queue as QueueModel;
use Illuminate\Queue\CallQueuedHandler;

class QueueServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        Queue::before(function (JobProcessing $event) {
            Log::info('before');
            Log::info($event->connectionName);
            // Log::info($event->job);
            Log::info(json_encode($event->data));
            // print_r($event->job);
            // foreach ($event->job as $key => $val) {
            //     Log::info($key);
            // }
            // die;
            // echo 11;
            // Log::info($event->job->payload());
            // $event->connectionName
            // $event->job
            // $event->job->payload()

            // QueueModel::start();
        });

        Queue::after(function (JobProcessed $event) {
            Log::info('after');
            Log::info($event->connectionName);
            Log::info(json_encode($event->data));
            // Log::info($event->job);
            // echo 22;
            // Log::info($event->job->payload());
            // $event->connectionName
            // $event->job
            // $event->job->payload()
            // QueueModel::end();
        });
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
